package com.ruoyi.web.controller.app.user;

import com.ruoyi.app.domain.bo.BuyGoodsBo;
import com.ruoyi.app.domain.vo.AppAssetVo;
import com.ruoyi.app.service.IAppAssetService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * APP用户资产信息
 *
 * @author heike
 * @date 2023-12-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/asset")
public class AppAssetController extends BaseController {

    private final IAppAssetService iAppAssetService;
    private final ISysConfigService sysConfigService;

    /**
     * 获取APP用户资产信息
     */
    @GetMapping()
    public R<AppAssetVo> info() {
        AppAssetVo appAssetVo = iAppAssetService.queryByUid(getUserId());
        String price = sysConfigService.selectConfigByKey("app.integral.price");
        appAssetVo.setIntegralPrice(price);
        return R.ok(appAssetVo);
    }



    /**
     * 积分兑换余额
     */
    @PostMapping("/coverBalance")
    public R<String> coverBalance(@RequestBody BuyGoodsBo buyGoodsBo) {
        iAppAssetService.coverBalance(buyGoodsBo);
        return R.ok("兑换成功");
    }


    /**
     * 购买商品 扣除余额
     */
    @PostMapping("/buyGoods")
    public R<String> buyGoods(@RequestBody BuyGoodsBo buyGoodsBo) {
        iAppAssetService.buyGoods(buyGoodsBo);
        return R.ok("购买成功");
    }
}
